package com.education.cms.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class UserUtils {
    @Autowired
    private RedisUtils redisUtils;
    /**
     * 获取登录用户的userId
     */
    public Integer getUserId(HttpServletRequest request){
        String ticket = (String) request.getSession().getAttribute("loginfo");
        String[] userInfo = redisUtils.get(ticket).split("-");
        Integer userId = Integer.parseInt(userInfo[0]);
        return userId;
    }
}
